package com.zgh.leo.signin611;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/*网络请求的线程
* */
public class HttpThread1 extends Thread {

    String url;
    String id;
    String password;
    public HttpThread1(String url,String id,String password){
       //初始化
        this.url=url;
        this.id=id;
        this.password=password;
    }
    //用doGet的方法发送请求
    private  void  doGet(){
        System.out.println("调用");
        url=url+"?id="+id+"&password="+password;
        try {
            URL httpUrl=new URL(url);

            URLConnection conn=  httpUrl.openConnection();
//            conn.set("POST");//请求的方式
            conn.setReadTimeout(5000);//请求超时的时间

            BufferedReader reader=new BufferedReader(new InputStreamReader(conn.getInputStream()));

            String str;
            StringBuffer sb=new StringBuffer();
            //读取服务器返回的信息（在不等于空的情况下继续往下读）
            while((str=reader.readLine())!=null){
                sb.append(str);//进行填充数据
            }
            System.out.println("返回的结果：");
            //将返回的数据打印出来
           System.out.println("result    "+sb.toString());

        } catch (MalformedURLException e) {
            e.printStackTrace();
        }  catch (IOException e) {
            e.printStackTrace();
        }

    }
    @Override
    public void run() {
        doGet();
    }
}
